<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
    <style>
        .market{
            font-size: 4em;
            color: skyblue;    
        }
        #app{
            width: 400px;
            height: 400px;
            border: 1px solid black;
        }
        button{
            width: 100px;
            height: 50px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="market">杂货铺</div>
        <button @click = 'jian(5)'>花费5元</button>
        <button @click = 'jian(10)'>花费10元</button>
        <button @click = 'jian(7)'>花费7元</button>
        <div class="market">拥有{{count}}元</div>
    </div>
    <script>
        const app = new Vue({
            el : '#app',
            data : {
                count : 100,
            },methods:{
                jian(n){
                    if (this.count > n) {
                        this.count -=n
                    }else{
                        alert('余额不足，无法购买')
                    }
                    
                }
            }
        });
    </script>
</body>

</html>